package com.rw.coco.handler.message.reply.handler.normal;

import com.rw.coco.handler.message.event.CocoMessageEvent;
import com.rw.coco.handler.message.reply.ReplyHandler;
import com.rw.coco.util.CocoReplyUtil;
import com.rw.coco.util.RandomUtil;

/**
 * 呼叫可可，给予的回复
 */
public class CocoHandler implements ReplyHandler {
    @Override
    public boolean trigger(CocoMessageEvent cocoMessageEvent) {
        String botName = CocoReplyUtil.REPLY_PROP.get(CocoReplyUtil.BOT_NAME);
        String message = cocoMessageEvent.getMessage();

        return message.startsWith(botName) && message.length() <= botName.length() + 1;
    }

    @Override
    public void handler(CocoMessageEvent cocoMessageEvent) {
        String botReply = CocoReplyUtil.REPLY_PROP.get(CocoReplyUtil.COCO_REPLY);
        String[] split = botReply.split("\n");

        // 随机一个回复
        int random = RandomUtil.getRandom().nextInt(split.length);
        cocoMessageEvent.sendBack(split[random]);
    }
}
